#结点类
class Node:
    def __init__(self,data):
        self.data = data
        self.next = None
        

#单链表类
class SqList:
    #创建单链表
    def __init__(self):
        self.head = None
    #添加元素
    def add(self,data):
        new_node = Node(data)
        new_node.next = self.head
        self.head = new_node
    #插入元素
    def insert(self,posele,data):
        if not self.head:
            return
        else:
            curNode = self.head
            while(curNode):
                if curNode.data == posele:
                    print("已执行")
                    new_node = Node(data)
                    new_node.data = data
                    new_node.next = curNode.next
                    curNode.next = new_node
                    return
                else:
                    curNode = curNode.next
    #删除元素
    def delete(self,posele):
          if not self.head:
              return
          else:
              preNode = None
              curNode = self.head
              count = 1
              while(curNode):
                  if curNode.data == posele:
                      if count==1:
                          self.head = curNode.next
                          return
                      else:
                          preNode.next = curNode.next
                          return
                  else:
                      count += 1
                      preNode = curNode
                      curNode = curNode.next
    #遍历单链表
    def outline(self):
        if not self.head:
            return
        else:
            curNone = self.head
            while(curNone):
                print(curNone.data)
                curNone = curNone.next
            print()
                
                
    
if __name__ == "__main__":
    while 1:
        print("1-创建单链表 2-增加元素")
        print("3-插入元素   4-删除元素")
        command = input("请输入您的指令:")
        if command == "1":
            sqlist = SqList()
            print("单链表创建成功\n1")
        elif command == "2":
            num = eval(input("您要插入的多少元素:"))
            for i in range(num):
                data = eval(input("请输入您的数据域值:"))
                sqlist.add(data)
            sqlist.outline()
        elif command == "3":
            posele = eval(input("您要到插入哪个结点元素:"))
            data = eval(input("您要插入的数据域的值:"))
            sqlist.insert(posele,data)
            sqlist.outline()
        elif command == "4":
            posele = eval(input("您要到删除哪个结点元素:"))
            sqlist.delete(posele)
            sqlist.outline()